//
//  BedCell.m
//  Nurse
//
//  Created by Sunny on 13-12-13.
//  Copyright (c) 2013年 RainSets. All rights reserved.
//

#import "BedCell.h"
#import "BedSmallCell.h"

@interface BedCell (){
    
}

@end

@implementation BedCell



- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        int w = 107;
        int h= 107;
        int x = 0;
        
        
        for (int i=0; i<3; i++) {
            NSArray *ibs =[[NSBundle mainBundle] loadNibNamed:@"BedSmallCell" owner:self options:nil];
            BedSmallCell* _btn  = [ibs objectAtIndex:0];
            _btn.frame =CGRectMake(x, 0, w, h);
            
            [_btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            
            [self addSubview:_btn1];
            
            _btn.tag=i+1;
            
            x= x+w;
            
            if (i==0) {
                self.btn1 = _btn;
            }else if(i==1){
                self.btn2 = _btn;
            }else if(i==2){
                self.btn3 = _btn;
            }
            
            [self addSubview:_btn];
        }
        
//        
//        NSArray *ibs =[[NSBundle mainBundle] loadNibNamed:@"BedSmallCell" owner:self options:nil];
//        _btn1  = [ibs objectAtIndex:0];
//        _btn1.frame =CGRectMake(x, 0, w, h);
//
//        [_btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
//        
//        [self addSubview:_btn1];
//        
//        x= x+w;
//        
//        _btn2 = [[[NSBundle mainBundle] loadNibNamed:@"BedSmallCell" owner:self options:nil] objectAtIndex:0];
//        _btn2.frame = CGRectMake(x, 0, w, h);
//        
//        [_btn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:_btn2];
//        
//        x= x+w;
//        _btn3 = [[[NSBundle mainBundle] loadNibNamed:@"BedSmallCell" owner:self options:nil] objectAtIndex:0];
//        _btn3.frame = CGRectMake(x, 0, w, h);
//
//        [_btn3 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:_btn3];
//        
//        
//        _btn1.tag = 1;
//        _btn2.tag = 2;
//        _btn3.tag = 3;
        
        
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setBedSeleted:(BedSeleted )bedSelected{
    _bedSeletedBlock =bedSelected;
}

-(void)btnClick:(UIButton *)sender{
    int tagIndex = sender.tag;
    
    if (_bedSeletedBlock) {
        _bedSeletedBlock(self.indexPath,tagIndex-1);
    }
}

//设计第几列不能点
-(void)setDisableColum:(int )columIndex{
  __weak  UIButton *btn  = nil;
    switch (columIndex) {
        case 0:
        {
            btn = _btn1;
        }
            break;
        case 1:
        {
             btn = _btn2;
        }
            break;
        case 2:
        {
            btn = _btn3;
        }
            break;
            
        default:
            break;
    }
    
    [btn setEnabled:NO];
}


-(void)setEnableColum:(int )columIndex{
    __weak  UIButton *btn  = nil;
    switch (columIndex) {
        case 0:
        {
            btn = _btn1;
        }
            break;
        case 1:
        {
            btn = _btn2;
        }
            break;
        case 2:
        {
            btn = _btn3;
        }
            break;
            
        default:
            break;
    }
    
    [btn setEnabled:YES];
}

@end
